package com.zyl.pts.web.controller;

import com.zyl.pts.config.anno.SystemLog;
import com.zyl.pts.config.enums.CodeAndMessageEnum;
import com.zyl.pts.config.result.Result;
import com.zyl.pts.domain.dto.DRDTO.DRUpdateOrAddDTO;
import com.zyl.pts.service.DRService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version v1.0
 * @ProjectName: product_source
 * @Package: com.zyl.pts.web.controller
 * @ClassName: DRController
 * @Description TODO(病症记录模块)
 * @Author 翟玉龙
 * @Date 2024/11/19-20:24
 */
@Tag(name = "病症记录模块", description = "病症记录模块")
@RestController
@RequestMapping("/diseaseRecord")
public class DRController {

    private final DRService drService;

    public DRController(DRService drService) {
        this.drService = drService;
    }

    /**
     * 查询所有病症类型信息接口
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "病症记录模块")
    @Operation(summary = "查询所有病症类型信息接口")
    @GetMapping("/queryAllDisease")
    public Result<?> getAllDiseaseType() {
        return Result.success(
                CodeAndMessageEnum.SUCCESS,
                drService.queryAllDiseaseRecord()
        );
    }

    /**
     * 分页多条件查询病症记录
     * @param drDId 病症id
     * @param drStatus 病症状态
     * @param pageNum 当前页码
     * @param pageSize 每页大小
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "分页多条件查询病症记录")
    @Operation(summary = "分页多条件查询病症记录")
    @GetMapping("/query")
    public Result<?> queryDiseaseRecord(
            @RequestParam(value = "drDId", required = false) Integer drDId,
            @RequestParam(value = "drStatus", required = false) String drStatus,
            @RequestParam(value = "pageNum") Integer pageNum,
            @RequestParam(value = "pageSize") Integer pageSize
    ) {
        return Result.success(
                CodeAndMessageEnum.SUCCESS,
                drService.queryDRPage(drDId, drStatus, pageNum, pageSize)
        );
    }

    /**
     * 新增或更新病症记录接口
     * @param drUpdateOrAddDTO 病症记录信息
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "新增或更新病症记录")
    @Operation(summary = "新增或更新病症记录接口")
    @PostMapping("/saveOrUpdate")
    public Result<?> addOrUpdateDiseaseRecord(
            @Validated @RequestBody DRUpdateOrAddDTO drUpdateOrAddDTO
    ) {
        return Result.success(
                drService.addOrUpdateDR(drUpdateOrAddDTO)
        );
    }

    /**
     * 根据记录ID删除病症记录接口
     * @param drId 病症记录id
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "根据记录ID删除病症记录")
    @Operation(summary = "根据记录ID删除病症记录接口")
    @DeleteMapping("/deleteById/{drId}")
    public Result<?> deleteDiseaseRecord(
            @PathVariable("drId") Integer drId
    ) {
        return Result.success(
                drService.deleteById(drId)
        );
    }

    /**
     * 批量删除病症记录接口
     * @param drIds 病症记录id集合
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "批量删除病症记录")
    @Operation(summary = "批量删除病症记录接口")
    @DeleteMapping("/deleteByIdAll")
    public Result<?> deleteBatchDiseaseRecord(
            @RequestBody List<Integer> drIds
    ) {
        return Result.success(
                drService.deleteByIds(drIds)
        );
    }
}
